#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef unsigned long long LL;
typedef long long NLL;
const int MAXN = 2e6+233;

uint x,y,z;
uint A,B,C;
uint arr[MAXN];

uint tang() {
    uint t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;
    t = x;
    x = y;
    y = z;
    z = t ^ x ^ y;
    return z;
}
LL gcd(LL a, LL b) {
    return (a%b==0? b : gcd(b, a%b));
}
LL lcm(LL a, LL b) {
    LL g = gcd(a, b);
    return a*b/g;
}
bool cmp(uint a, uint b) {
    return a > b;
}

int main() {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    int T;
    cin>>T;
    int n;
    for(int cas = 1; cas <= T; ++cas) {
        scanf("%u %u %u %u", &n, &A, &B, &C);
        x = A; y = B; z = C;
        priority_queue<LL, vector<LL>, greater<LL> > pq;
        for (int i=0; i<n; ++i) {
            LL t = tang();
            if (pq.size()<100) {
                pq.push(t);
            }
            else {
                if (t > pq.top()) {
                    pq.pop();
                    pq.push(t);
                }
            }
        }
        int cnt = 0;
        while (!pq.empty()) {
            arr[cnt++] = pq.top();
            pq.pop();
        }
        LL res = 0;
        int len = std::min(cnt, 100);
        for (int i=0; i<len; ++i) {
            for (int j=0; j<i; ++j) {
                LL t = lcm(arr[i], arr[j]);
                if (res < t) res = t;
            }
        }
        printf("Case #%d: ", cas);
        cout<<res<<"\n";
    }
    return 0;
}
